﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//
using System.Data;
using System.Data.SqlClient;

namespace WinForm_Test
{
    public  class SQLHelper
    {
        private SqlConnection _SqlConnection;

        public SQLHelper()
        {
            _SqlConnection = new SqlConnection(
            @"Data Source=THINKPAD-ANDING\AN_DING;password=anding;user id=sa;initial catalog=test");
        }
        public DataTable ExecuteSqlStr(string sqlString, out string message)
        {
            message = string.Empty;
            try
            {
                _SqlConnection.Open();
                SqlCommand com = new SqlCommand(sqlString, _SqlConnection);
                SqlDataAdapter sda = new SqlDataAdapter(com);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                return dt;
            }
            catch (Exception e)
            {
                message = e.Message;
                return null;
            }
            finally
            {
                _SqlConnection.Close();
            }
        }
    }
}
